package com.star.modules.sys.service;

import com.jeesite.common.collect.MapUtils;
import com.jeesite.common.entity.Page;
import com.jeesite.common.mapper.BeanMapper;
import com.jeesite.modules.sys.utils.DictUtils;
import com.star.modules.sys.base.BizDataResult;
import com.star.modules.sys.entity.ShInfo;
import com.star.modules.sys.enums.DictEnum;
import com.star.modules.sys.enums.ResultEnum;
import com.star.modules.sys.excetion.ApiException;
import com.star.modules.sys.vo.InforMationVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;


/**
 * 首页服务类
 */
@Service
@Transactional(readOnly = true)
public class InforMationService {

    @Autowired
    private ShInfoService  shInfoService;

    /**
     * 首页业务层
     *
     * @return
     */
    public BizDataResult getInforMation(ShInfo shInfo , Page page) {
        Page pages = null;
        try {
            shInfo.setStatus(ShInfo.STATUS_NORMAL);
            pages = shInfoService.findPage(page,shInfo);
            pages.setList(BeanMapper.mapList(pages.getList(),InforMationVo.class));
            Map<String,Object> otherData = MapUtils.newHashMap();
            otherData.put("menuColStr",DictUtils.getDictLabel(DictEnum.INFO_TYPE.getCode()
                    ,shInfo.getMenuCol()+"", IndexService.DEFAULT_LABEL));
            pages.setOtherData(otherData);
        } catch (Exception e) {
            throw new ApiException(e);
        }
        return BizDataResult.createResult(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg(), pages);
    }
}
